import request from "@/utils/request";
import axios from "axios";

const api_name = "/paike";

export default {
    getpaikeForTheDate(date) {
        return request({
            url: `${api_name}/getpaikeForTheDate/list/${date}`,
            method: "get",
        });

    },
    updatePaiKe(data) {
        return request({
            url: `${api_name}/lessonRecord`,
            method: "post",
            data: data
        })
    },
    startPaike(params) {
        return new Promise((res, err) => {
            let url = `http://localhost:8080/paike/startPaike`;
            axios
                .post(url, params, {
                    responseType: "blob", // 指定响应类型为二进制数据
                })
                .then((response) => {
                    const blob = new Blob([response.data], {
                        type: "application/vnd.ms-excel",
                    });
                    const url = window.URL.createObjectURL(blob);
                    const link = document.createElement("a");
                    link.href = url;
                    link.setAttribute("download", `${model}-${date}.xlsx`);
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    res('排课初步完成，请检查下载的excel表格，检查无误后请进行上传！')
                })
                .catch((error) => {
                    // 处理错误
                    err('排课失败！')
                });
        })
    },
}